package edu.zut.cs.software.example.Menu.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import edu.zut.cs.software.example.domain.BaseTreeEntity;

/**
 * 
 * @author chen ming yang
 *
 */
@Entity
@Table(name = "mainmenu")
//@NamedQueries({ @NamedQuery(name = "MainMenu.getRoot", query = "select m from MainMenu m where m.parent is null") })
public class MainMenu  extends BaseTreeEntity<MainMenu, Long>  {

	private static final long serialVersionUID = 3758955488592290572L;

	@Column
	private String title;
	@Column
	private String path;
	// main's children
	// 级联保存、更新、删除、刷新;延迟加载。当删除用户，会级联删除该用户的所有文章
	// 拥有mappedBy注解的实体类为关系被维护端
	// mappedBy="mainMenu"中的author是Article中的author属性
	@OneToMany(mappedBy = "mainMenu", cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
//	@JsonManagedReference
	private List<SubMenu> sList;
	
	

	public MainMenu() {
		super();
	}

	public MainMenu(String title, String path, List<SubMenu> sList) {
		super();
		this.title = title;
		this.path = path;
		this.sList = sList;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public List<SubMenu> getsList() {
		return sList;
	}

	public void setsList(List<SubMenu> sList) {
		this.sList = sList;
	}

	@Override
	public String toString() {
		return "MainMenu [title=" + title + ", path=" + path + ", id=" + id + "]";
	}

}
